
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>国际化和本地化 &#8212; Django 3.2.11.dev 文档</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../../genindex.html" />
    <link rel="search" title="搜索" href="../../search.html" />
    <link rel="next" title="翻译" href="translation.html" />
    <link rel="prev" title="发送邮件" href="../email.html" />



 
<script src="../../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../index.html">Django 3.2.11.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../index.html">Home</a>  |
        <a title="Table of contents" href="../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../genindex.html">Index</a>  |
        <a title="Module index" href="../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="../email.html" title="发送邮件">previous</a>
     |
    <a href="../index.html" title="使用 Django" accesskey="U">up</a>
   |
    <a href="translation.html" title="翻译">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="topics-i18n-index">
            
  <div class="section" id="s-internationalization-and-localization">
<span id="internationalization-and-localization"></span><h1>国际化和本地化<a class="headerlink" href="#internationalization-and-localization" title="永久链接至标题">¶</a></h1>
<div class="toctree-wrapper compound">
</div>
<div class="section" id="s-overview">
<span id="overview"></span><h2>概况<a class="headerlink" href="#overview" title="永久链接至标题">¶</a></h2>
<p>国际化和本地化的目标是让同一站点为不同的用户提供定制化的语言和格式服务。</p>
<p>Django 完整支持 <a class="reference internal" href="translation.html"><span class="doc">翻译文本</span></a>， <a class="reference internal" href="formatting.html"><span class="doc">格式化日期，时间和数字</span></a> 以及 <a class="reference internal" href="timezones.html"><span class="doc">时区</span></a>。</p>
<p>实际上，Django 做了两件事：</p>
<ul class="simple">
<li>它允许开发者和模板作者指定应用的哪个部分应该被翻译或格式化为本地语言，符合本地文化。</li>
<li>它根据用户的配置利用钩子本地化 Web 应用。</li>
</ul>
<p>翻译依赖于目标语言，而格式化规则依赖于目标国家。此信息由浏览器的 <code class="docutils literal notranslate"><span class="pre">Accept-Language</span></code> 头提供。但是，时区并不容易获得。</p>
</div>
<div class="section" id="s-definitions">
<span id="definitions"></span><h2>定义<a class="headerlink" href="#definitions" title="永久链接至标题">¶</a></h2>
<p>单词国际化（internationalization）和本地化（localization）总是令人迷惑；以下是个简单的定义：</p>
<dl class="glossary docutils">
<dt id="term-internationalization">国际化</dt>
<dd>为本地化准备软件。通常由开发者完成。</dd>
<dt id="term-localization">本地化</dt>
<dd>编写翻译和本地格式化。通常由翻译者完成。</dd>
</dl>
<p>更多细节请查阅 <a class="reference external" href="https://www.w3.org/International/questions/qa-i18n">W3C Web Internationalization FAQ</a> ， <a class="reference external" href="https://en.wikipedia.org/wiki/Internationalization_and_localization">Wikipedia article</a>  或  <a class="reference external" href="https://www.gnu.org/software/gettext/manual/gettext.html#Concepts">GNU gettext documentation</a> 。</p>
<div class="admonition warning">
<p class="first admonition-title">警告</p>
<p class="last">翻译和格式化分别由 <a class="reference internal" href="../../ref/settings.html#std:setting-USE_I18N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_I18N</span></code></a> 和 <a class="reference internal" href="../../ref/settings.html#std:setting-USE_L10N"><code class="xref std std-setting docutils literal notranslate"><span class="pre">USE_L10N</span></code></a> 控制。但是，这两个功能都涉及国际化和本地化。这两个配置的名字是 Django 的历史原因所导致。</p>
</div>
<p>下面是一些术语，可以帮助我们处理通用语言：</p>
<dl class="glossary docutils">
<dt id="term-locale-name">locale name</dt>
<dd>区域名称，可以是 <code class="docutils literal notranslate"><span class="pre">ll</span></code> 形式的语言规范，也可以是 <code class="docutils literal notranslate"><span class="pre">ll_CC</span></code> 形式的语言和国家组合规范。例如：<code class="docutils literal notranslate"><span class="pre">it</span></code>、<code class="docutils literal notranslate"><span class="pre">de_AT</span></code>、<code class="docutils literal notranslate"><span class="pre">es</span></code>、<code class="docutils literal notranslate"><span class="pre">pt_BR</span></code>、<code class="docutils literal notranslate"><span class="pre">sr_Latn</span></code>。语言部分总是用小写。国家部分如果超过两个字符，则首字母大写，否则全部大写。分隔符为下划线。</dd>
<dt id="term-language-code">language code</dt>
<dd>代表语言名。浏览器使用这个格式来在 <code class="docutils literal notranslate"><span class="pre">Accept-Language</span></code> HTTP header 里发送浏览器接受的语言名。比如：<code class="docutils literal notranslate"><span class="pre">it</span></code>, <code class="docutils literal notranslate"><span class="pre">de-at</span></code>, <code class="docutils literal notranslate"><span class="pre">es</span></code>, <code class="docutils literal notranslate"><span class="pre">pt-br</span></code> 。语言代码一般用小写表示，但是 HTTP <code class="docutils literal notranslate"><span class="pre">Accept-Language</span></code> header 不区分大小写。用破折号来间隔。</dd>
<dt id="term-message-file">message file</dt>
<dd>一个消息文件是文本文件，代表一种语言，包含所有可用的 <a class="reference internal" href="#term-translation-string"><span class="xref std std-term">translation strings</span></a> ，以及它们如何在给定的语言里表示。消息文件的文件扩展名是 <code class="docutils literal notranslate"><span class="pre">.po</span></code> 。</dd>
<dt id="term-translation-string">translation string</dt>
<dd>可以翻译的文字。</dd>
<dt id="term-format-file">format file</dt>
<dd>格式文件是一个 Python 模块，用于定义本地数据格式。</dd>
</dl>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">国际化和本地化</a><ul>
<li><a class="reference internal" href="#overview">概况</a></li>
<li><a class="reference internal" href="#definitions">定义</a></li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="../email.html"
                        title="上一章">发送邮件</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="translation.html"
                        title="下一章">翻译</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/topics/i18n/index.txt"
            rel="nofollow">显示源代码</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">12月 07, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="../email.html" title="发送邮件">previous</a>
     |
    <a href="../index.html" title="使用 Django" accesskey="U">up</a>
   |
    <a href="translation.html" title="翻译">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>